<?php
namespace Admin\Model;
use Think\Model;

class DepartmentModel extends AbstractModel {

	public $_validate = array(
        array('Name','require','请输入部门名称',Model::MUST_VALIDATE)
        //array('BossID','number','请选择负责人',Model::MUST_VALIDATE),
        //array('Address','require','请输入地址',Model::MUST_VALIDATE),
        //array('Phone','number','请输入手机号码',Model::MUST_VALIDATE)
    );
	
	protected $_auto = array(
    	array('AddTime', 'getInputTime',3,'callback')
  	);
  	
  	public function getInputTime(){
		return date('Y-m-d H:i:s');
	}
	
	public function getSelectorTree($id){		
		$sql = "SELECT Name AS name, ID AS id, ParentID AS pid, (SELECT ID FROM Department WHERE ParentID = a.ID AND IsDel = 0 LIMIT 1) AS Sonid FROM Department AS a WHERE ParentID = {$id} AND IsDel = 0 ORDER BY OrderNO ASC";
		$res = $this->query($sql);
		foreach($res AS $k => $v){
			if(!empty($v['Sonid'])){
				$res[$k]['isParent'] = "true";
				//$res[$k]['icon'] = __APP__."./img/diy/22.png";
			} 
		}
		//print_r($res);
		return $res;
	}
}

?>